package cn.alex.sso.project.controller;

import cn.alex.sso.framework.annotations.OperatLog;
import cn.alex.sso.framework.constant.ActionConstant;
import cn.alex.sso.framework.constant.ModuleConstant;
import cn.alex.sso.framework.core.Result;
import cn.alex.sso.project.entity.SysRole;
import cn.alex.sso.project.service.SysRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色管理
 *
 * @author Alex
 * @date 2024/10/12 23:11
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/role")
public class SysRoleController {
    private final SysRoleService baseService;

    /**
     * 获取分页列表
     */
    @GetMapping("/getPage")
    public Result getPage(SysRole entity) {
        return Result.ok(baseService.getPage(entity));
    }

    /**
     * 获取全部数据
     */
    @GetMapping("/getAll")
    public Result getAll() {
        return Result.ok(baseService.list());
    }

    /**
     * 获取详情
     */
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Long id) {
        return Result.ok(baseService.getById(id));
    }

    /**
     * 新增
     */
    @PostMapping
    @OperatLog(module = ModuleConstant.ROLE, action = ActionConstant.ADD)
    public Result add(@RequestBody SysRole entity) {
        baseService.add(entity);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PutMapping
    @OperatLog(module = ModuleConstant.ROLE, action = ActionConstant.EDIT)
    public Result edit(@RequestBody SysRole entity) {
        baseService.edit(entity);
        return Result.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping
    @OperatLog(module = ModuleConstant.ROLE, action = ActionConstant.REMOVE)
    public Result del(@RequestBody List<Long> ids) {
        baseService.del(ids);
        return Result.ok();
    }
}
